package com.shelpe.services.sustainer.configuration;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.scope.StepScope;
import org.springframework.boot.autoconfigure.batch.BatchProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

import com.shelpe.services.sustainer.step.BlankEnderStep;
import com.shelpe.services.sustainer.step.BlankStarterStep;
import com.shelpe.services.sustainer.step.InprogressCleanerStep;
import com.shelpe.services.sustainer.step.InprogressRecordStep;

@Configuration
@EnableScheduling
@EnableBatchProcessing
public class JobConfiguration{


	@Bean
	public SustainerBatchConfigurer SustainerBatchConfigurer(BatchProperties properties, DataSource ds, EntityManagerFactory entityManagerFactory){
		SustainerBatchConfigurer configurer = new SustainerBatchConfigurer(properties, ds, entityManagerFactory);
		configurer.initialize();
		return configurer;
	}
	
	@Bean
	public BlankStarterStep starter(JobRepository jobRepository) {
		BlankStarterStep step = new BlankStarterStep();
		step.setJobRepository(jobRepository);
		return step;
	}

	@Bean
	public BlankEnderStep ender(JobRepository jobRepository) {
		BlankEnderStep step = new BlankEnderStep();
		step.setJobRepository(jobRepository);
		return step;
	}
	
	@Bean
	public InprogressRecordStep inprogressRecorder(JobRepository jobRepository) {
		InprogressRecordStep step = new InprogressRecordStep();
		step.setJobRepository(jobRepository);
		return step;
	}

	@Bean
	public InprogressCleanerStep inprogressCleaner(JobRepository jobRepository) {
		InprogressCleanerStep step = new InprogressCleanerStep();
		step.setJobRepository(jobRepository);
		return step;
	}

	@Bean
	public static StepScope scope() {
		return new StepScope();
	}
	
}
